<template>
	<view class="news-content">
		<view class="block search-block">
			<view class="iconfont icon-sousuo"></view>
			<input v-model="keyword" @confirm="getList" @blur="getList" placeholder-class="inputPlaceholder" placeholder="请输入关键字"  />
		</view>
		<view class="block list-block">
			<view v-if="newsList.length==0" style="margin: 0;" class="empty">暂无数据</view>
			<block v-else>
				<navigator hover-class="none" :url="'/pages/news/detail?id='+item.id" v-for="(item,index) in newsList" :key="item.id" class="news-item" >
					<image mode="aspectFill" :src="item.cover_photo" class="news-photo"></image>
					<view class="news-info">
						<view class="news-title">{{item.title}}</view>
						<view class="news-create-time">发布日期：{{item.create_time}}</view>
					</view>
				</navigator>
			</block>
		</view>
	</view>
</template>

<script>
	import {getArticleList} from '@/api/article.js';
	export default{
		data(){
			return{
				newsList:[
				],
				keyword:'',
			}
		},
		methods:{
			getList(){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				getArticleList({keyword:this.keyword,type:10,pageNum:1,pageSize:1000}).then((res)=>{
					uni.hideLoading();
					if(res.status==1){
						this.newsList=res.data;
					}else{
						this.utils.showToast(res.message);
					}
				}).catch((res)=>{
					uni.hideLoading();
					this.utils.showToast('加载失败！');
				})
			}
		},
		onShow() {
			this.getList();
		}
	}
</script>

<style lang="scss" scoped>
	.news-content{
		padding: 30rpx;
		.block{
			box-shadow:0 0 10px 0 #dedede;
			width: 100%;
		}
		.search-block{
			padding: 16rpx 0;
			margin-bottom: 20rpx;
			border-radius: 60rpx;
			display: flex;
			align-items: center;
			.iconfont{
				flex-grow: 0;
				margin: 0 20rpx;
				color: #999;
				font-size: 36rpx;
			}
			input{
				flex-grow: 1;
				font-size: 28rpx;
			}
		}
		.list-block{
			padding: 20rpx;
			border-radius: 20rpx;
			.news-item{
				width: 100%;
				padding: 30rpx 0;
				border-bottom: 1px solid #efefef;
				display: flex;
				flex-direction: row;
				.news-photo{
					width: 140rpx;
					height: 140rpx;
					margin-right: 20rpx;
				}
				.news-info{
					width: calc(100% - 160rpx);
					height: 140rpx;
					position: relative;
					.news-title{
						text-align: justify;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}
					.news-create-time{
						position: absolute;
						bottom: 0rpx;
						left: 0;
						color: #999;
						font-size: 28rpx;
					}
				}
			}
			.news-item:last-child{
				border-bottom: none;
			}
		}
	}
</style>